package com.lanyun.aicorrectassistant.domain.gradingResults.impl;

import com.lanyun.aicorrectassistant.basic.entity.GradingResults;
import com.lanyun.aicorrectassistant.basic.service.GradingResultsService;
import com.lanyun.aicorrectassistant.controller.admin.gradingResults.vo.GradingResultsRequestPageVO;
import com.lanyun.aicorrectassistant.controller.admin.gradingResults.vo.GradingResultsRequestVO;
import com.lanyun.aicorrectassistant.controller.admin.gradingResults.vo.GradingResultsResponseVO;
import com.lanyun.aicorrectassistant.convert.GradingResultsConvert;
import com.lanyun.aicorrectassistant.domain.gradingResults.GradingResultsDomainService;
import com.lanyun.aicorrectassistant.basic.bean.PageResult;
import com.lanyun.aicorrectassistant.enums.IsDeletedFlagEnum;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import java.util.List;

/**
 * AI批改结果表领域服务实现
 * @author makejava
 * @version 1.0
 * @date 2025-05-12 01:54:01
 */
@Service
public class GradingResultsDomainServiceImpl implements GradingResultsDomainService {

    @Resource
    private GradingResultsService gradingResultsService;

    @Override
    public PageResult<GradingResultsResponseVO> page(GradingResultsRequestPageVO requestPageVO) {
        PageResult<GradingResultsResponseVO> pageResult = new PageResult<>();
        GradingResults queryEntity = GradingResultsConvert.INSTANCE.convert(requestPageVO);
        queryEntity.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getVal());
        
        List<GradingResults> entities = gradingResultsService.page(queryEntity, 
            requestPageVO.getStart(), requestPageVO.getPageSize());
        
        if (entities.isEmpty()) {
            return pageResult;
        }
        
        Long count = gradingResultsService.count(queryEntity);
        List<GradingResultsResponseVO> vos = GradingResultsConvert.INSTANCE.convertEntityToRespList(entities);
        
        pageResult.setResult(vos);
        pageResult.setTotal(count.intValue());
        return pageResult;
    }

    @Override
    public Boolean update(GradingResultsRequestVO requestVO) {
        GradingResults entity = GradingResultsConvert.INSTANCE.convert(requestVO);
        return gradingResultsService.update(entity) != 0;
    }

    @Override
    public Boolean delete(Long id) {
        GradingResults entity = new GradingResults();
        entity.setId(id);
        entity.setIsDeleted(IsDeletedFlagEnum.DELETED.getVal());
        return gradingResultsService.update(entity) != 0;
    }

    @Override
    public Boolean insert(GradingResultsRequestVO requestVO) {
        GradingResults entity = GradingResultsConvert.INSTANCE.convert(requestVO);
        return gradingResultsService.insert(entity) != 0;
    }

    @Override
    public GradingResultsResponseVO get(Long id) {
        GradingResults entity = gradingResultsService.queryById(id);
        return GradingResultsConvert.INSTANCE.convert(entity);
    }
}
